
    <?php
    $req = "SELECT count(*) FROM tag";
    $req = mysql_query($req);
    $data = mysql_result($req, 0);


    if ($data > 0) {
        ?>
        <div id="tagcloud">
        <?php
        define("MIN_SIZE", 9);
        define("MAX_SIZE", 36);

        $req = "SELECT nom, count(*) as nombre FROM tag GROUP BY nom ORDER BY nombre DESC LIMIT 0,30";
        $req = mysql_query($req) or die(mysql_error());

        $min = 0;
        $max = 0;

        while ($tag = mysql_fetch_assoc($req)) {
            if ($tag['nombre'] < $min)
                $min = $tag['nombre'];
            if ($tag['nombre'] > $max)
                $max = $tag['nombre'];
            $tags[] = $tag;
        }
        shuffle($tags);
        $min_size = MIN_SIZE;
        $max_size = MAX_SIZE;

        foreach ($tags as $tag) {
            $tag['taille'] = intval($min_size + (($tag['nombre'] - $min) * (($max_size - $min_size) / ($max - $min))));
            $tags_extended[] = $tag;
        }

        foreach ($tags_extended as $tag) :
            ?>
            <a href="tag--<?php echo $tag['nom']; ?>" style="font-size:<?php echo $tag['taille']; ?>px"><?php echo $tag['nom']; ?></a>
            <?php
        endforeach;
        ?>
        </div>
        <?php
    }
    ?>
